package hongcaosp.app.android.user.settings.share;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;

import hongcaosp.app.android.R;
import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.bean.UserInfo;
import hongcaosp.app.android.user.qrcode.MineQRCodeActivity;
import hongcaosp.app.android.user.qrcode.QRCodeUtil;
import hongcaosp.app.android.user.qrcode.QRUserBean;
import xlj.lib.android.base.component.BaseActivity;
import xlj.lib.android.base.utils.DensityUtils;
import xlj.lib.android.base.utils.JsonUtil;
import xlj.lib.android.base.utils.ScreenUtils;

/**
 * 分享我的个人主页
 */
public class ShareHomeActivity extends BaseActivity {

    public static void launcher(Context context) {
        context.startActivity(new Intent(context,ShareHomeActivity.class));
    }

    private ImageView qrCodeIV;
    private TextView nickTV;
    private Bitmap qrBm;

    @Override
    protected void initData(Intent intent) {
        UserInfo userInfo = UserToken.getDefault().getUser();
        nickTV.setText(userInfo.getNickName());
        QRUserBean userBean = new QRUserBean();
        userBean.setUserId(userInfo.getId());
        userBean.setNickName(userInfo.getNickName());
        final String content = JsonUtil.toJsonStr(userBean);
        Glide.with(this).load(userInfo.getImage()).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                int size = ScreenUtils.getScreenWidth(ShareHomeActivity.this) - DensityUtils.dip2px(ShareHomeActivity.this,200);
                Bitmap bitmap = QRCodeUtil.createQRCodeWithLogo(content,size,resource);
                qrBm = bitmap;
                qrCodeIV.setImageBitmap(bitmap);
            }
        });
    }

    @Override
    protected void initView() {
        qrCodeIV = findViewById(R.id.qrcode_iv);
        nickTV = findViewById(R.id.nick);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_share_home;
    }
}
